import { Customer } from '../types';
import { formatAmount } from './numberFormat';

/**
 * 获取客户优先级
 * @param customer 客户信息
 * @returns 优先级 'high' | 'medium' | 'low'
 */
export const getCustomerPriority = (customer: Customer): 'high' | 'medium' | 'low' => {
  const riskLevel = customer.risk_preference;
  
  if (riskLevel?.includes('R4') || riskLevel?.includes('R5')) {
    return 'high';
  }
  if (riskLevel?.includes('R2') || riskLevel?.includes('R3')) {
    return 'medium';
  }
  return 'low';
};

/**
 * 获取客户标签
 * @param customer 客户信息
 * @returns 标签数组
 */
export const getCustomerTags = (customer: Customer): string[] => {
  return [
    customer.risk_level,
    customer.investment_experience
  ].filter((tag): tag is string => Boolean(tag));
};

/**
 * 格式化客户资产信息
 * @param customer 客户信息
 * @returns 格式化的资产信息
 */
export const formatCustomerAssets = (customer: Customer): string => {
  const totalAssets = customer.total_investment || customer.account_balance || 0;
  return formatAmount(totalAssets);
};

/**
 * 获取客户风险等级显示文本
 * @param customer 客户信息
 * @returns 风险等级显示文本
 */
export const getRiskLevelDisplayText = (customer: Customer): string => {
  const riskLevel = customer.risk_preference || customer.risk_level;
  
  const riskLevelMap: Record<string, string> = {
    'R1': '保守型',
    'R2': '稳健型', 
    'R3': '平衡型',
    'R4': '积极型',
    'R5': '激进型'
  };
  
  return riskLevelMap[riskLevel || ''] || riskLevel || '未知';
}; 